package com.rd.p2p.mobile.user;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.util.CollectionUtils;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.AccountBankService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.dto.AccountBank;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.UserIdentifyModel;

/**
 * 用户认证信息
 * 
 * @author wuhuan
 */
public class MobileUserIdentifyAction extends BaseAction<UserIdentifyModel> implements ModelDriven<UserIdentifyModel> {
    
    @Resource
    private AccountBankService accountBankService;
    
	/**
	 * 邮箱/认证
	 *
	 * @return
	 * @throws Exception
	 */
	@Action(value = "/mobile/usercenter/useridentify/email", results = {
			@Result(name = "email", type = "ftl", location = "/mobile/member/useridentify/email.html") })
	public String emailActive() throws Exception {
		return "email";
	}

	/**
	 * 银行认证
	 *
	 * @return
	 * @throws Exception
	 */
	@Action(value = "/mobile/usercenter/useridentify/bank", results = {
			@Result(name = "bank", type = "ftl", location = "/mobile/member/useridentify/bank.html") })
	public String bank() throws Exception {
	    User user = getSessionUser();
	    boolean hasBank = false;
	    boolean hasBindPhone = false;
	    String mobilePhone = null;
	    List<AccountBank> bankList = accountBankService.list(user.getUserId());
        if (!CollectionUtils.isEmpty(bankList)) {
            hasBank = true;
            for (AccountBank bank : bankList) {
                if (StringUtils.isNotEmpty(bank.getMobilephone())) {
                    mobilePhone = bank.getMobilephone();
                    hasBindPhone = true;
                    break;
                }
            }
        }
        int bankNum = SystemConfigHelper.getIntegerValue(SystemConfigHelper.Nid.BANK_NUM);
        request.setAttribute("bankNum", bankNum);
        request.setAttribute("hasBindPhone", hasBindPhone);
        request.setAttribute("bankList", bankList);
        request.setAttribute("hasBank", hasBank);
        request.setAttribute("mobilePhone", mobilePhone);
        return "bank";
	}

	/**
	 * 身份证认证
	 *
	 * @return
	 * @throws Exception
	 */
	@Action(value = "/mobile/usercenter/useridentify/cardid", results = {
			@Result(name = "cardid", type = "ftl", location = "/mobile/member/useridentify/cardid.html") })
	public String cardid() throws Exception {
		return "cardid";
	}

}
